<?php header("Content-Type:text/html;   charset=utf-8"); ?>
<script type="text/javascript">
    $(function(){
        $("a[href='#maximize']").trigger("click");
        $("#txtTitles").bind("blur",checkTitleNewArticle);
        $("#txtContent").bind("blur",checkContentNewArticle);
        $("#txtAuthor").bind("blur",checkAuthorNewArticle);
        $("#submitArticle").bind("click",submitArticle);
        loadNewArticle();

    });
    function submitArticle(){
        if(checkTitleNewArticle()==false)
            return;
        if(checkContentNewArticle()==false)
            return;
        if(checkAuthorNewArticle()==false)
            return;

        if(checkUidNewActicle()==false)
            return;

        /*if(checkColumnNewArticle()==false)
            return;*/

        var column = $("#txtColumns").val();
        var titles = $("#txtTitles").val();
        var content = $("#txtContent").val();
        var keyword = $("#txtKeyword").val();
        var author = $("#txtAuthor").val();
        var uid = $("#txtUid").val();
        var hdidsms = $("#hdidsms").val();
        var txtPhoto = $("#txtPhoto").val();
        var txtShow = $("input[name='is_display']:checked").val();
        var txtSort = $("#txtSort").val();
        var params = {
            id:hdidsms,
            column_id:column,
            title:titles,
            content:content,
            author:author,
            keyword:keyword,
            uid:uid,
            url:txtPhoto,
            show:txtShow,
            sort:txtSort
        };

        $.ajax({
            type:"post",
            url:"admin.php/article/addArticle",
            dataType:"json",
            data:params,
            success:function(data){
                parent.loadArticle();
                alert("提交成功");
                $("#btnCloseNewArticle").trigger("click");
            }
        });
    }


    function checkTitleNewArticle(){
        var title = $("#txtTitles").val();
        if(IsEmpty(title)){
            SetError("txtTitles","标题不能为空");
            return false;
        }
        var len = title.length;
        if(len>100){
            SetError("txtTitles","最多100字");
            return false;
        }
        SetOK("txtTitles");
        return true;
    }
    function checkContentNewArticle(){
        var content = $("#txtContent").val();
        if(IsEmpty(content)){
            SetError("txtContent","内容不能为空");
            return false;
        }
        SetOK("txtContent");
        return true;
    }

    function checkAuthorNewArticle()
    {
        var content = $("#txtAuthor").val();
        if(IsEmpty(content)){
            SetError("txtAuthor","作者不能为空");
            return false;
        }
        SetOK("txtAuthor");
        return true;
    }

    function checkColumnNewArticle()
    {
        var column = $("#txtColumns").val();
        if(IsEmpty(column)){
            SetError('txtColumns','分类不能为空');
            return false;
        }
        SetOK('txtColumns');
        return true;
    }

    function checkUidNewActicle()
    {
        var uid = $("#txtUid").val();

        if(!IsEmpty(uid)){
            uidarr = new Array();
            uidarr = uid.split(',');
            for(var i=0;i<uidarr.length;i++){
                if(isNaN(uidarr[i])){
                    SetError('txtUid','请输入正确的格式');
                    return false;
                }

            }
        }
        SetOK('txtUid');
        return true;


    }

    function loadNewArticle(){
        var id = $("#hdidsms").val();
        if(id==0)
            return;

        //$("div.buttonActive").hide();
        $("div.button").attr("style","margin-left:260px;")
        var params = {id:id};
        $.ajax({
            type:"post",
            url:"admin.php/article/loadNewArticle",
            dataType:"json",
            data:params,
            success:function(data){
                $("#txtTitles").val(data.title);
                $("#txtContent").val(data.content);
                $("#txtUid").val(data.uids);
                $("#txtAuthor").val(data.author);
                $("#txtKeyword").val(data.keyword);
                $("#txtColumns").val(data.column_id);
                $("#txtPhoto").val(data.url);
                $("input[value="+data.is_show+"]").attr("checked",true);
                $("#txtSort").val(data.sort);
            }
        });
    }
    <?php $timestamp = time();?>
    $(function() {
        $('#file_upload').uploadify({
            'formData'     : {
                'timestamp' : '<?php echo $timestamp;?>',
                'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
            },
            'swf'      : 'uploadify/uploadify.swf',
            'uploader' : '<?php echo base_url();?>uploadify/uploadify.php',
            'buttonImage': 'images/sczp_inp.jpg',
            'onUploadSuccess' : function(file, data, response) {
                var aa='';
                if(response!=0){
                    $("#txtPhoto").val(data);
                }

            }
        });
    });
</script>
<style type="text/css">
    .uploadify-button {
        background-color: transparent;
        border: none;
        padding: 0;
    }
    .uploadify:hover .uploadify-button {
        background-color: transparent;
    }
    #file_upload{margin-top: -5px;float: left;}
</style>
<div class="pageContent">
    <form class="pageForm required-validate">
        <div class="pageFormContent" style="; width: 98%;"
             layoutH="56">
            <table class="tableNewUser">
                <tr>
                    <td>所属分类：</td>
                    <td>
                        <select id="txtColumns">
                            <option value="">请选择</option>
                            <?php foreach($column as $item):?>

                            <option value="<?php echo $item['id'];?>"><?php echo $item['name'];?></option>

                            <?php endforeach;?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>标题：</td>
                    <td><input id="txtTitles" type="text" style="width:500px" value="" /></td>
                </tr>
                <tr>
                    <td>作者：</td>
                    <td><input id="txtAuthor" type="text" style="width:250px" value="" /></td>
                </tr>

                <tr>
                <tr>
                    <td>接收人：</td>
                    <td><input id="txtUid" type="text" style="width:500px" value="" /><span style="margin-left:10px;">例：1,2,3,注:只限微访谈添加接收人uid，如果多个给一个人添加多个微访谈默认只显示最后一次添加的。</span></td>
                </tr>

                <tr>
                    <td>关键字：</td>
                    <td style='line-height: 130px'>
                        <textarea id="txtKeyword" style="width:500px;height:100px" rows="" cols=""></textarea>
                    </td>
                </tr>
                <tr>
                    <td style='line-height: 50px'>头像：</td>
                    <td>
                        <div class="unit">
                            <input id="txtPhoto" type="text" style="width:300px" value="" /><input id="file_upload" name="file_upload" type="file" multiple="true">注:只限微访谈添加头像
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>内容：</td>
                    <td>
                        <div class="unit">
                        <textarea id="txtContent" class="editor" rows="20" cols="100" tools="simple"></textarea>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>排序：</td>
                        <td>
                            <input id="txtSort" type="text" style="width:40px" value="" />
                        </td>
                </tr>
                <tr>
                    <td>是否显示：</td>
                    <td >
                            <input type="radio" value="1" name="is_display" style="width:50px;" checked="checked">显示<input style="width:50px;" type="radio" value="0" name="is_display" />隐藏
                    </td>
                </tr>

                <tr>
                    <td colspan="2" style='line-height: 40px'>&nbsp;&nbsp;</td>
                </tr>
            </table>
            <input type="hidden" id="hdidsms" value="<?php if(isset($_GET["id"])) print $_GET["id"]; else print 0;?>">

            <div class="buttonActive" style="width: 120px; margin-left: 180px;">
                <div class="buttonContent">
                    <button id="submitArticle" type="button" style="width: 80px">提 交</button>
                </div>
            </div>

            <div class="button" style="text-align:right">
                <div class="buttonContent" style="text-align: right">
                    <button id="btnCloseNewArticle" type="button" class="close"
                            style="width: 80px">取 消</button>
                </div>
            </div>
        </div>
    </form
</div>